package com.jerry.base.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 用户代理
 *
 * @author Jerry
 * @since 2024/7/17 15:46
 */
public class UserServiceHandler implements InvocationHandler {

    private Object target;

    public UserServiceHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        long start = System.currentTimeMillis();

        Object result = method.invoke(target, args);

        long end = System.currentTimeMillis();
        System.out.println("执行" + method.getName() + "耗时：" + (end - start) + "ms");
        return result;
    }
}
